import React, { Component } from 'react'
// 导入仓库
import store1 from '../../store1';
// console.log('store1', store1);
//导入商品相关的actions
import { addCarAction, addProAction } from '../../store1/actions/shopAction'
//导入用户相关的actions
import { addAgeAction } from '../../store1/actions/userAction'
export default class Father extends Component {
    constructor() {
        super()
        this.state = {
            ...store1.getState()
        }

        store1.subscribe(() => {
            this.setState({
                ...store1.getState()
            })
        })
    }
    render() {
        const { shop, user } = this.state
        return (
            <div>
                {/* 商品数据 */}
                <ul>
                    {
                        shop.prolist.map(item => <li key={item.id}>{item.name}</li>)
                    }
                </ul>
                <p>pronum:{shop.pronum}</p>
                <p><button onClick={() => {
                    store1.dispatch(addCarAction(
                        {
                            id: shop.prolist[shop.prolist.length - 1].id + 1,
                            name: '兰蔻-防晒霜',
                            price: 599
                        }
                    ))
                }}>添加商品</button></p>
                <p><button onClick={() => {
                    store1.dispatch(addProAction())
                }}>pronum++</button></p>
                <hr />
                {/* 用户信息 */}
                <p>
                    {user.userinfo.name}--{user.userinfo.age}
                </p>
                <p>usernum:{user.usernum}</p>
                <p><button onClick={() => {
                    store1.dispatch(addAgeAction(10))
                }}>age++</button></p>

            </div>
        )
    }
}
